import redis


def main():
    # Redis客户端对象
    client = redis.Redis(host='106.15.205.83', port=6379,
                         password='1234QWEasd')
    print(client)
    client.set('username', 'hello world', ex=300)
    print(client.ttl('username'))
    print(client.get('username'))  # b'hello world'
    print(client.get('username').decode())  # 解码
    """
    str：字符串
    bytes：字节串。上面的b'hello world'就是字节串
    """
    client.set('kfxname', '孔飞翔', ex=300)
    print(client.get('kfxname'))
    print(client.get('kfxname').decode())
    client.set('cty', 21, ex=300)   # set是字符串方法
    client.incr('cty')
    client.incrby('cty', 20)
    print(int(client.get('cty').decode()))  # 是个str类型，转为int


if __name__ == '__main__':
    main()
